https://leetcode-cn.com/problems/longest-palindromic-substring/

class Solution {
public:
    string longestPalindrome(string s) {
        if(s.empty()) return "";

        int maxlen = 1;
        int maxindex = 0;
        for(int i = 0 ; i < s.size(); i++)
        {
            int cur, right, left;
            cur = left = right = i;  
            while(left > 0){
                if(s[left - 1] == s[cur]) left--;
                else break;  
            }       

            while(right < s.size() - 1){
                if(s[right + 1] == s[cur]) right++;
                else break;
            }   

            while(left > 0 && right < s.size() - 1){
                if(s[left - 1] == s[right + 1]) {
                    left--;
                    right++;
                } 
                else break;
            }
            if(right - left + 1 > maxlen){
                maxlen = right - left + 1;
                maxindex = left;
            }
        }
        return s.substr(maxindex, maxlen);
    }
};